<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
use think\Session;

/**
 * Class Index 主页模块
 * @package app\admin\controller
 */
class Index extends Controller
{
    /**
     * @param Request $request 主页
     * @return mixed
     */
    public function index(Request $request)
    {
        $role_id = Session::get('auth.role_id');
        $admin_id = Session::get('auth.aid');
        $role_names = Db::table('admin_role')->where('role_id', $role_id)
            ->field('role_name')
            ->find();
        $data['role_name'] = $role_names['role_name'];
        $data['menu'] = Db::table('admin a')
            ->join('admin_role ar', 'a.role_id=ar.role_id')
            ->join('role_access ra', "ar.role_id=ra.role_id")
            ->join("access ac", "ra.access_id=ac.access_id")
            ->where('a.role_id', $role_id)
            ->where('a.aid', $admin_id)
            ->where("ac.parent_id", 0)->select();
        foreach ($data['menu'] as &$vo) {
            $vo['childnodes'] = Db::table('access')->where('parent_id', $vo['access_id'])->select();
        }
        return view('', $data);
    }

    /**
     * @param Request $request 欢迎页
     * @return mixed
     */
    public function welcome(Request $request)
    {
        $data['ip'] = $_SERVER['REMOTE_ADDR'];
        $data['server_name'] = $_SERVER['SERVER_NAME'];
        $data['server_ip'] = $_SERVER['SERVER_ADDR'];
        $data['file'] = __FILE__;
        $data['time'] = date('Y-m-d H:i:s');
        $this->assign('data', $data);
        return $this->fetch();
    }
}